#ifndef QMC2SSERVERDIALOG_H
#define QMC2SSERVERDIALOG_H

#include <QDialog>
#include <QProcess>
#include "def.h"
#include "thread.h"
#include "smtp.h"
#include "report.h"
#include <QTcpServer>
#include "serverform.h"

namespace Ui {
class QMC2SServerDialog;
}

class QMC2SServerDialog : public QDialog
{
    Q_OBJECT

public:
    explicit QMC2SServerDialog(QWidget *parent = 0);
    ~QMC2SServerDialog();
    void init();
    void connDB();
    void closeEvent(QCloseEvent *event);
    void showMessage(char *msg);
    void createActions();
    void createTrayIcon();
    void doTimer();
    void deamon();
    void analysis();
    void initDeviceHost();
    void alert(QString msg);
    QString read_data(char *s, QTcpSocket &socket);
    void start();
    void stop();


 private slots:
    void on_startButton_clicked();

    void on_stopButton_clicked();

    void on_exitButton_clicked();

    void iconActivated(QSystemTrayIcon::ActivationReason reason);
    void on_backButton_clicked();
    void showMessage();
    void receive_msg(const QString str);
    void receive_progress_value(const int value);
    void log_print_msg(const QString str);
    void do_send_email(const QString file);
    void on_language_comboBox_currentTextChanged(const QString &arg1);
    void execQuery(QString sql);
    void ScreenTest();
    void start_process();
    void finish_process(int exitCode, QProcess::ExitStatus exitStatus);
    void start_read_output();
    void start_read_err_output();
    void readMessage();
    void newConnect();
    void on_serverRadioButton_clicked();

private:
    Ui::QMC2SServerDialog *ui;
    QSqlDatabase db;
    Config config;
    QSqlQueryModel *model;
    QList<Device> dev_list;
    Thread ths[50];
    QSettings *settings;

    QSystemTrayIcon *trayIcon;
    QMenu *trayIconMenu;
    QAction *minimizeAction;
    QAction *maximizeAction;
    QAction *restoreAction;
    QAction *quitAction;
    QAction *startAction;
    QAction *stopAction;
    Smtp *smtp;
    QString user;
    QString password;
    QString host;
    uint port;
    QString to;
    QString from;
    QString subject;
    Report *report;
    int dev_test_count; //统计已测试的设备
    QProcess *process;
    int device_count; // 设备数量
    QString dev_ip;
    enum {WANDA_MODEL, LEONIS_MODEL, SERVER_MODEL};

    bool flag;
    QTcpServer tcpServer;
    QTcpSocket *tcpSocket;
    ServerForm *serverForm;

 //    int end_status[50];  // 用来控制线程每天只跑一次
//    int thread_ids[50];  // 线程编号
//    QTimer timer[50];   //定时器
};

#endif // QMC2SSERVERDIALOG_H
